﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL_HealthInsurance;
using DTO_HealthInsurance;
using System.Data;
namespace HealthInsuranceMgm
{
    public partial class demo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack){
                Loaddata();
               
            }

        }
        public void Loaddata() { //load to grid
           BLLCompany obj = new BLLCompany();
            GridView1.DataSource= obj.ListCompany();
            GridView1.DataBind();
        }
        public void LoaddataToTextbox(int CompanyId) {
            //load to textbox
            BLLCompany obj = new BLLCompany();
            DTOCompanyDetail objDto = new DTOCompanyDetail();//
            objDto.CompanyId = CompanyId;//   cho nay la gan gia tri cho CompanyId.thong qua doi tuong objDto.tuc la property set o ben DTO 
            DataTable dt = obj.GetCompanyById(objDto);
            TextBox1.Text = dt.Rows[0]["CompanyId"].ToString();
            TextBox2.Text = dt.Rows[0]["CompanyName"].ToString();
            TextBox3.Text = dt.Rows[0]["Address"].ToString();
            TextBox4.Text = dt.Rows[0]["Phone"].ToString();
            TextBox5.Text = dt.Rows[0]["CompanyUrl"].ToString();

                
        }

        protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            int CompanyId =Int32.Parse(GridView1.DataKeys[e.NewSelectedIndex].Value.ToString());
            LoaddataToTextbox(CompanyId);
            

        }
    }
}